﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
public partial class Stock_StockInReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindReport(BuildReportDt());
    }

    private DataSet BuildReportDt()
    {
        StockInDataSet ds = new StockInDataSet();
        DataRow dr1 = ds.StockInTable.NewRow();
        dr1["StockInOrderNum"] = "liu";
        dr1["StcokInDate"] = "2012-12-12";
        dr1["CompanyNum"] = "liu";
        dr1["VendorSellOutNum"] = "liu";
        dr1["StockInMan"] = "liu";
        dr1["StockValidMan"] = "liu";
        dr1["Status"] = "liu";
        dr1["TM"] = "";
        dr1["PreCompanyNum"] = "123456";

        ds.StockInTable.Rows.Add(dr1);
        ds.StockInTable.AcceptChanges();


        DataRow dr2 = ds.StockInDetail.NewRow();
        dr2["item"] = "1";
        dr2["TM"] = "aa";
        dr2["ProductCode"] = "1";
        dr2["ProductName"] = "aa";
        dr2["Color"] = "1";
        dr2["ColorCode"] = "aa";
        dr2["Unit"] = "1";
        dr2["MH"] = "aa";
        dr2["SellPrice"] = "1";
        dr2["Price"] = "1";
        dr2["Qty"] = "1";
        dr2["Account"] = "1";
        dr2["CreateDate"] = "2012-12-12";
        //
        ds.StockInDetail.Rows.Add(dr2);
        ds.StockInDetail.AcceptChanges();

        return ds;
    }

    private void BindReport(DataSet ds)
    {
        string url = Server.MapPath("~/ReportTemp/StockInReport.rpt");
        CrystalReportSource1.Report.FileName = url;
       
        CrystalReportSource1.ReportDocument.Load(url);
        CrystalReportSource1.ReportDocument.SetDataSource(ds);
        CrystalReportSource1.DataBind();

        CrystalReportViewer1.ReportSource = CrystalReportSource1;
        CrystalReportViewer1.DataBind();
    }
}